<?php
    include ("includes/config.php");    
    include ("includes/connection.php");
    include ("includes/database.php");
    
    $post = mysql_fetch_assoc(getPost($_GET["id"]));
    
    if (!$post) {
        die("Tidak dapat menemukan tulisan yang dimaksud!");
    }
    else {
        
        /* Set page title */
        $title = $post["title"];
        
        /* Header */
        include ("header.php");   
?>
        <h1><?php echo $post["title"]; ?></h1>   
        <h3>Published at: <?php echo $post["published_time"]; ?></h3>
        <?php echo $post["body"]; ?>
        
        <?php
            if (isset($_GET["comment_success"]) && $_GET["comment_success"]) {
        ?>
                <h3>Thank you. Your comment has been saved.</h3>
        <?php
            }
        ?>
        
        <form action="<?php echo $CONFIG["base_url"] . "post-comment.php" ?>" method="POST">
            <input type="hidden" name="post_id" value="<?php echo $_GET["id"]; ?>" />

            <label>Name</label>
            <input type="text" name="name" placeholder="Input Your Name"/> <br />

            <label>Email</label>
            <input type="text" name="email"/> <br />

            <label>Your Comment</label>
            <textarea name="comment"></textarea> <br />   

            <input type="submit" value="Submit"/>
        </form>
        
        <?php
            /* Display Comments */
            $comments = getComments($_GET["id"]);
            while ($comment = mysql_fetch_assoc($comments)){
        ?>
            <h2><?php echo $comment["name"] ?></h2>
            <?php echo $comment["comment"] ?>
        <?php
            }
        ?>
        
<?php
    include ("footer.php");
?>
            
<?php
    }
?>